package com.csxh.web.model.mybatis;

public abstract class Condition {

	public enum OrderMode {
		ASC, DESC
	}

	public enum LogicOp {
		AND, // (exp1) AND (exp2)
		OR, // (exp1) OR (exp2)
		NOT// NOT (exp1)
	}

	public enum RelationOp {
		EQ, // field = ?
		LG, // field > ?
		LT, // field < ?
		LGEQ, // field >= ?
		LTEQ, // field <= ?
		LIKE, // field LIKE %?%
		NOT_LIKE, // field NOT LIKE %?%
		IN, // field IN(?,?,?)
		NOT_IN, // field NOT IN(?,?,?)
		BETWEEN// field BETWEEN ? AND ?
	}

	private String[] fieldNames;
	private String[] fieldValues;
	private RelationOp relationOp = RelationOp.EQ;
	private LogicOp logicOp = LogicOp.AND;

	public Condition() {
		
	}
	
	public void setFieldNames(String... fieldNames) {
		this.fieldNames = fieldNames;
	}

	public String getSelectFields(){
		if(null==this.fieldNames || this.fieldNames.length==0){
			return "*";
		}
		StringBuilder sb=new StringBuilder();
		for(String field : this.fieldNames){
			sb.append("`").append(field).append("`").append(",");
		}
		
		sb=sb.deleteCharAt(sb.length()-1);
		
		return sb.toString();
		
	}
	
	public abstract String getTable();


	private String where;
	public void setWhere(String where) {
		this.where = where;
	}
	public String getWhere() {
		return where;
	}
	
	private Object idValue;

	public void setIdValue(Object idValue) {
		this.idValue = idValue;
	}

	public Object getIdValue() {
		return idValue;
	}

	private String orderField;
	private OrderMode orderMode = OrderMode.DESC;

	public void setOrderField(String orderField) {
		this.orderField = orderField;
	}

	public void setOrderMode(OrderMode orderMode) {
		this.orderMode = orderMode;
	}

	public String getOrderField() {
		return orderField;
	}

	public String getOrderMode() {
		return orderMode.toString();
	}

	private int offset;
	private int limit;
	
	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}


}
